import baiduDemo.BaiduDemo;
import baiduDemo.BaiduSearchDto;
import dto.SearchFaceDto;
import faceService.SearchFace;
import org.apache.commons.collections.map.HashedMap;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/10/23.
 */
public class verifyExport {

    public static void main(String[] args) throws Exception {
        BaiduDemo baiduDemo = new BaiduDemo();
        SearchFace searchFace = new SearchFace();
        List<String> group = new ArrayList<String>();
        group.add("test");

        baiduDemo.identify("C:\\Users\\Administrator\\Desktop\\facePic\\s1\\1.bmp", group);

        String filePath = "C:\\Users\\Administrator\\Desktop\\facePic";

        Map<String, String> tecentResult = new HashedMap();
        Map<String, String> tecentTF = new HashedMap();
        Map<String, String> baiduResult = new HashedMap();
        Map<String, String> baiduTF = new HashedMap();
        List<String> nameList = new ArrayList<String>();
        File root = new File(filePath);
        File[] files = root.listFiles();
        for (File file : files) {
            if (!file.isDirectory()) {
                String name = file.getName();
                name = name.replaceAll("\\.", "");
                name = name.replaceAll("png", "");
                name = name.replaceAll("jpg", "");
                name = name.replaceAll("bmp", "");
                String actResult = name.split("_")[1];
                SearchFaceDto searchFaceDto = searchFace.searchFace(file.getAbsolutePath());
                if (searchFaceDto.getMessage().equals("OK")) {
                    String result = searchFaceDto.getData().getCandidates().get(0).getPerson_id();
                    String confidence = searchFaceDto.getData().getCandidates().get(0).getConfidence();
                    String tf = "";
                    if ((result.equalsIgnoreCase(actResult) && Double.valueOf(confidence) > 80)
                            || (!result.equalsIgnoreCase(actResult) && Double.valueOf(confidence) < 80)) {
                        tf = "RIGHT";
                    } else {
                        tf = "WRONG";
                    }
                    tecentResult.put(name, result + ":   " + confidence);
                    tecentTF.put(name, tf);
                } else {
                    tecentResult.put(name, "Exception");
                    tecentTF.put(name, "Exception");
                }
                BaiduSearchDto baiduSearchDto = new BaiduSearchDto();
                if (baiduSearchDto.getResult().equals("OK")) {
                    String tf = "";
                    if ((baiduSearchDto.getPersonID().equalsIgnoreCase(actResult) && Double.valueOf(baiduSearchDto.getConfindece()) > 80)
                            || (!baiduSearchDto.getPersonID().equalsIgnoreCase(actResult) && Double.valueOf(baiduSearchDto.getConfindece()) < 80)) {
                        tf = "RIGHT";
                    } else {
                        tf = "WRONG";
                    }
                    baiduResult.put(name, baiduSearchDto.getPersonID() + ":   " + baiduSearchDto.getConfindece());
                    baiduTF.put(name,  tf);
                } else {
                    baiduResult.put(name, "Exception");
                    baiduTF.put(name, "Exception");
                }

                nameList.add(name);
            }
        }




    }
}
